<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>highlight.sh</title>
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (Bash) - Theme (Breeze Dark)"/>
</head><body style="background-color:#232629;color:#cfcfc2"><pre>
<span style="color:#7a7c7d;">#! /bin/sh</span>
<span style="color:#7a7c7d;"># This is a test script for the Katepart Bash Syntax Highlighting by</span>
<span style="color:#7a7c7d;">#	Wilbert Berendsen.  This is not runnable !!!</span>


<span style="color:#7a7c7d;"># The highlighting recognizes basic types of input, and has a few special cases that</span>
<span style="color:#7a7c7d;"># are all in FindCommands.  The main objective is to create really proper nesting of</span>
<span style="color:#7a7c7d;"># (multiline) strings, variables, expressions, etc.</span>



<span style="color:#7a7c7d;"># ============== Tests: ===============</span>

<span style="color:#7a7c7d;"># basic types:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">'single quoted string'</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;double quoted string&quot;</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">$'string with esc</span><span style="color:#2980b9;">\a</span><span style="color:#f44f4f;">pes</span><span style="color:#2980b9;">\x0d</span><span style="color:#f44f4f;">in it'</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">$&quot;</span><span style="color:#f44f4f;">string meant to be translated&quot;</span>


<span style="color:#7a7c7d;"># comments:</span>
<span style="color:#7a7c7d;"># this is a comment</span>
<span style="color:#7a7c7d;">#this too</span>
<span style="color:#7f8c8d;">echo</span> this is#nt a comment
<span style="color:#8e44ad;">dcop</span> kate EditInterface#1 <span style="color:#7a7c7d;">#this is</span>
<span style="color:#8e44ad;">grep</span> -e <span style="color:#f44f4f;">&quot;^default/linux/amd64/&quot;</span> <span style="font-weight:bold;">|</span><span style="color:#0099ff;font-weight:bold;">\ </span><span style="color:#7a7c7d;">#this is a comment</span>
<span style="color:#8e44ad;">mkdir</span> this<span style="color:#2980b9;">\ </span>isnt<span style="color:#2980b9;">\ </span>#a<span style="color:#2980b9;">\ </span>comment
<span style="color:#8e44ad;">mkdir</span> this<span style="color:#2980b9;">\ </span>isnt<span style="color:#2980b9;">\\\;</span>#a<span style="color:#2980b9;">\ </span>comment
<span style="color:#8e44ad;">mkdir</span> this<span style="color:#2980b9;">\\</span> <span style="color:#7a7c7d;">#is a comment</span>

<span style="color:#7a7c7d;"># brace expansion</span>
<span style="color:#8e44ad;">mv</span> my_file.<span style="color:#2980b9;">{JPG,jpg}</span>


<span style="color:#7a7c7d;"># special characters are escaped:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#2980b9;">\(</span>output<span style="color:#2980b9;">\)</span> <span style="color:#2980b9;">\&amp;\|</span> <span style="color:#2980b9;">\&gt;</span> <span style="color:#2980b9;">\&lt;</span> <span style="color:#2980b9;">\&quot;</span> <span style="color:#2980b9;">\'</span> <span style="color:#2980b9;">\*</span>


<span style="color:#7a7c7d;"># variable substitution:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$filename</span>.ext
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$filename_ext</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">${filename}</span>_ext
<span style="color:#7f8c8d;">echo</span> text<span style="color:#27aeae;">${array[$subscript]}</span>.text
<span style="color:#7f8c8d;">echo</span> text<span style="color:#27aeae;">${array[</span><span style="color:#f44f4f;">&quot;string&quot;</span><span style="color:#27aeae;">]}</span>.text
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">${!prefix*}</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">${!redir}</span>
<span style="color:#7f8c8d;">echo</span> short are <span style="color:#27aeae;">$_</span>, <span style="color:#27aeae;">$$</span>, <span style="color:#27aeae;">$?</span>, <span style="color:#27aeae;">${@}</span>, etc.
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">${variable/</span>a<span style="color:#27aeae;">/</span>d<span style="color:#27aeae;">}</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">${1:-</span>default<span style="color:#27aeae;">}</span>


<span style="color:#7a7c7d;"># expression subst:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$((</span> cd &lt;&lt; ed + 1 <span style="color:#27aeae;">))</span>


<span style="color:#7a7c7d;"># command subst:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$(</span><span style="color:#8e44ad;">ls</span> -l<span style="color:#27aeae;">)</span>
<span style="color:#7f8c8d;">echo</span> <span style="font-weight:bold;">`</span><span style="color:#8e44ad;">cat</span> myfile<span style="font-weight:bold;">`</span>


<span style="color:#7a7c7d;"># file subst:</span>
<span style="color:#7f8c8d;">echo</span> $(&lt;<span style="color:#27aeae;">$filename</span>)
<span style="color:#7f8c8d;">echo</span> $(&lt;/path/to/myfile)

<span style="color:#7a7c7d;"># process subst:</span>
<span style="color:#8e44ad;">sort</span> &lt;(<span style="color:#0099ff;font-weight:bold;">show_labels</span>) <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">sed</span> <span style="color:#f44f4f;">'s/a/bg'</span> &gt; my_file.txt 2&gt;&amp;1


<span style="color:#7a7c7d;"># All substitutions also work in strings:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;subst </span><span style="color:#27aeae;">${in}</span><span style="color:#f44f4f;">side string&quot;</span>  <span style="color:#f44f4f;">'not $inside this ofcourse'</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;The result is </span><span style="color:#27aeae;">$((</span> <span style="color:#27aeae;">$a</span> + <span style="color:#27aeae;">$b</span> <span style="color:#27aeae;">))</span><span style="color:#f44f4f;">. Thanks!&quot;</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;Your homedir contains </span><span style="font-weight:bold;">`</span><span style="color:#8e44ad;">ls</span> <span style="color:#27aeae;">$HOME</span> <span style="font-weight:bold;">|</span><span style="color:#8e44ad;">wc</span> -l<span style="font-weight:bold;">`</span><span style="color:#f44f4f;"> files.&quot;</span>


<span style="color:#7a7c7d;"># Escapes in strings:</span>
<span style="color:#27aeae;">p=</span><span style="color:#f44f4f;">&quot;String </span><span style="color:#2980b9;">\`</span><span style="color:#f44f4f;"> with </span><span style="color:#2980b9;">\$</span><span style="color:#f44f4f;"> escapes </span><span style="color:#2980b9;">\&quot;</span><span style="color:#f44f4f;"> &quot;</span>;


<span style="color:#7a7c7d;"># keywords are black, builtins dark purple and common commands lighter purple</span>
<span style="font-weight:bold;">set</span>
<span style="color:#7f8c8d;">exit</span>
<span style="color:#8e44ad;">login</span>


<span style="color:#7a7c7d;"># Other colorings:</span>
<span style="color:#8e44ad;">error()</span> <span style="font-weight:bold;">{</span>
	<span style="color:#8e44ad;">cat</span> /usr/bin/lesspipe.sh
	<span style="color:#0099ff;font-weight:bold;">runscript</span> &gt;<span style="font-weight:bold;">&amp;</span> <span style="color:#0099ff;font-weight:bold;">redir.bak</span>
	<span style="color:#7f8c8d;">exec</span> 3&gt;&amp;4
<span style="font-weight:bold;">}</span>


<span style="color:#7a7c7d;"># do - done make code blocks</span>
<span style="font-weight:bold;">while</span><span style="color:#7f8c8d;"> [</span> <span style="color:#27aeae;">$p</span> <span style="color:#27ae60;">-lt</span> <span style="color:#27aeae;">$q</span><span style="color:#7f8c8d;"> ]</span> 
<span style="font-weight:bold;">do</span>
	<span style="color:#8e44ad;">chown</span> 0644 <span style="color:#27aeae;">$file</span>.<span style="color:#27aeae;">$p</span>
<span style="font-weight:bold;">done</span>


<span style="color:#7a7c7d;"># braces as well</span>
<span style="color:#0099ff;font-weight:bold;">run_prog</span> <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">sort</span> -u <span style="font-weight:bold;">|</span>
<span style="font-weight:bold;">{</span>
	<span style="color:#7f8c8d;">echo</span> Header
	<span style="font-weight:bold;">while</span> <span style="color:#7f8c8d;">read</span> <span style="color:#27aeae;">a</span> <span style="color:#27aeae;">b</span> <span style="color:#27aeae;">d</span>
	<span style="font-weight:bold;">do</span>
		<span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$a</span>/<span style="color:#27aeae;">$b</span>/<span style="color:#27aeae;">$c</span>
	<span style="font-weight:bold;">done</span>
	<span style="color:#7f8c8d;">echo</span> Footer
<span style="font-weight:bold;">}</span>


<span style="color:#7a7c7d;"># Any constructions can be nested:</span>
<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;A long string with </span><span style="color:#27aeae;">$(</span>
	<span style="font-weight:bold;">if</span><span style="color:#7f8c8d;"> [</span> <span style="color:#27aeae;">$count</span> <span style="color:#27ae60;">-gt</span> 100<span style="color:#7f8c8d;"> ]</span> ; <span style="font-weight:bold;">then</span>
		<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;much&quot;</span>
	<span style="font-weight:bold;">else</span>
		<span style="color:#7f8c8d;">echo</span> <span style="color:#f44f4f;">&quot;not much&quot;</span>
	<span style="font-weight:bold;">fi</span> <span style="color:#27aeae;">)</span><span style="color:#f44f4f;"> substitutions.&quot;</span> <span style="font-weight:bold;">;</span>


<span style="color:#7a7c7d;"># Even the case construct is correctly folded:</span>
<span style="color:#7f8c8d;">test</span> -f blaat <span style="font-weight:bold;">&amp;&amp;</span>
<span style="font-weight:bold;">(</span>	<span style="color:#0099ff;font-weight:bold;">do_something</span>
	<span style="font-weight:bold;">case</span> <span style="color:#27aeae;">$p</span><span style="font-weight:bold;"> in</span>
		*bak<span style="font-weight:bold;">)</span>
			<span style="color:#0099ff;font-weight:bold;">do_bak</span> <span style="color:#27aeae;">$p</span>
			<span style="font-weight:bold;">;;</span>
		*<span style="font-weight:bold;">)</span>
			<span style="color:#0099ff;font-weight:bold;">dont_bak</span> <span style="color:#27aeae;">$p</span>
			<span style="font-weight:bold;">;;</span>
	<span style="font-weight:bold;">esac</span>
<span style="font-weight:bold;">)</span> <span style="color:#7a7c7d;"># despite the extra parentheses in the case construction.</span>


<span style="color:#7a7c7d;"># variable assignments:</span>
<span style="color:#27aeae;">DIR=</span>/dev
<span style="color:#27aeae;">p=</span><span style="font-weight:bold;">`</span><span style="color:#8e44ad;">ls</span><span style="font-weight:bold;">`</span>
<span style="color:#27aeae;">LC_ALL=</span><span style="color:#f44f4f;">&quot;nl&quot;</span> <span style="color:#8e44ad;">dcop</span> <span style="color:#f44f4f;">'kate*'</span>
<span style="color:#27aeae;">_VAR=</span>val
<span style="color:#27aeae;">ARR=(</span>this is an array<span style="color:#27aeae;">)</span>
<span style="color:#27aeae;">ARR2=([this]=</span>too <span style="color:#27aeae;">[and]=</span><span style="color:#f44f4f;">&quot;this too&quot;</span><span style="color:#27aeae;">)</span>
<span style="color:#27aeae;">usage=</span><span style="color:#f44f4f;">&quot;</span><span style="color:#27aeae;">$0</span><span style="color:#f44f4f;"> -- version </span><span style="color:#27aeae;">$VERSION</span>
<span style="color:#f44f4f;">Multiple lines of output</span>
<span style="color:#f44f4f;">can be possible.&quot;</span>
<span style="color:#27aeae;">ANSWER=</span>yes	<span style="color:#7a7c7d;"># here 'yes' isn't highlighed as command</span>


<span style="color:#7a7c7d;"># Some commands expect variable names, these are colored correctly:</span>
<span style="color:#7f8c8d;">export</span> <span style="color:#27aeae;">PATH=</span>/my/bin:<span style="color:#27aeae;">$PATH</span> <span style="color:#27aeae;">BLAAT</span>
<span style="color:#7f8c8d;">export</span> <span style="color:#27aeae;">A</span> <span style="color:#27aeae;">B</span> <span style="color:#27aeae;">D</span>
<span style="color:#7f8c8d;">local</span> <span style="color:#27aeae;">p=</span>3  <span style="color:#27aeae;">x</span>  <span style="color:#27aeae;">y=</span><span style="color:#f44f4f;">'\'</span>
<span style="color:#7f8c8d;">read</span> <span style="color:#27aeae;">x</span> <span style="color:#27aeae;">y</span> <span style="color:#27aeae;">z</span> &lt;&lt;&lt; <span style="color:#27aeae;">$hallo</span>
<span style="color:#7f8c8d;">unset</span> <span style="color:#27aeae;">B</span>
<span style="color:#7f8c8d;">declare</span> -a <span style="color:#27aeae;">VAR1</span> <span style="color:#27aeae;">VAR2</span> <span style="font-weight:bold;">&amp;&amp;</span> <span style="color:#7f8c8d;">exit</span>
<span style="color:#7f8c8d;">declare</span> <span style="color:#27aeae;">less</span> <span style="color:#27aeae;">a</span> <span style="font-weight:bold;">&amp;&amp;</span> <span style="color:#0099ff;font-weight:bold;">b</span> 

<span style="color:#7a7c7d;"># options are recoqnized:</span>
<span style="color:#8e44ad;">zip</span> -f=file.zip
<span style="color:#0099ff;font-weight:bold;">./configure</span>  --destdir=/usr
<span style="color:#8e44ad;">make</span>  destdir=/usr/


<span style="color:#7a7c7d;"># [[ and [ correctly need spaces to be regarded as structure,</span>
<span style="color:#7a7c7d;"># otherwise they are patterns (currently treated as normal text)</span>
<span style="font-weight:bold;">if</span><span style="color:#7f8c8d;"> [</span> <span style="color:#f44f4f;">&quot;</span><span style="color:#27aeae;">$p</span><span style="color:#f44f4f;">&quot;</span> <span style="color:#27ae60;">==</span> <span style="color:#f44f4f;">&quot;&quot;</span><span style="color:#7f8c8d;"> ]</span> ; <span style="font-weight:bold;">then</span>
	<span style="color:#8e44ad;">ls</span> /usr/bin/[a-z]*
<span style="font-weight:bold;">elif [[</span> <span style="color:#27aeae;">$p</span> <span style="color:#27ae60;">==</span> 0<span style="font-weight:bold;"> ]]</span> ; <span style="font-weight:bold;">then</span>
	<span style="color:#8e44ad;">ls</span> /usr/share/<span style="color:#27aeae;">$p</span>
<span style="font-weight:bold;">fi</span>

<span style="color:#7a7c7d;"># Fixed:</span>
<span style="color:#8e44ad;">ls</span> a[ab]*		<span style="color:#7a7c7d;"># dont try to interprete as assignment with subscript (fixed)</span>
<span style="color:#0099ff;font-weight:bold;">a</span>[ab]
<span style="color:#27aeae;">a[ab]=</span>sa


<span style="color:#7a7c7d;"># Here documents are difficult to catch:</span>
<span style="color:#8e44ad;">cat</span> &gt; myfile &lt;&lt; __EOF__
You're right, this is definitely no bash code
But ls more <span style="color:#27aeae;">$parameters</span> should be expanded.
__EOF__


<span style="color:#7a7c7d;"># quoted:</span>
<span style="color:#8e44ad;">cat</span> &lt;&lt; &quot;EOF&quot; <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">egrep</span> <span style="color:#f44f4f;">&quot;this&quot;</span> &gt;&amp;4   <span style="color:#7a7c7d;"># the rest of the line is still considered bash source</span>
You're right, this is definitely no bash code
But ls more $parameters should be expanded. :-&gt;
EOF


<span style="color:#7a7c7d;"># indented:</span>
<span style="font-weight:bold;">if</span> <span style="color:#8e44ad;">true</span>
<span style="font-weight:bold;">then</span>
	<span style="color:#8e44ad;">cat</span> &lt;&lt;- EOF
		Indented text with a <span style="color:#27aeae;">$dollar</span> or <span style="color:#2980b9;">\$</span>two
	EOF
<span style="font-weight:bold;">elif</span><span style="color:#7f8c8d;"> [</span> <span style="color:#27ae60;">-d</span> <span style="color:#27aeae;">$file</span><span style="color:#7f8c8d;"> ]</span>; <span style="font-weight:bold;">then</span>
	<span style="color:#8e44ad;">cat</span> &lt;&lt;- &quot;EOF&quot;
		Indented text without a $dollar
	EOF
<span style="font-weight:bold;">fi</span>


<span style="font-weight:bold;">case</span> 1<span style="font-weight:bold;"> in</span> 
2<span style="font-weight:bold;">)</span> <span style="color:#7f8c8d;">echo</span> xxx<span style="font-weight:bold;">;</span>
<span style="font-weight:bold;">;;</span>
1<span style="font-weight:bold;">)</span> <span style="color:#7f8c8d;">echo</span> yyy<span style="font-weight:bold;">;</span>
<span style="font-weight:bold;">esac</span>

<span style="color:#8e44ad;">ls</span> <span style="color:#7a7c7d;">#should be outside of case 1 folding block</span>

<span style="font-weight:bold;">for</span> <span style="color:#0099ff;font-weight:bold;">i</span> in <span style="font-weight:bold;">`</span><span style="color:#8e44ad;">ls</span> tests/auto/output/*.html<span style="font-weight:bold;">`</span><span style="font-weight:bold;">;</span> <span style="font-weight:bold;">do</span>
    <span style="color:#27aeae;">refFile=</span><span style="font-weight:bold;">`</span><span style="color:#7f8c8d;">echo</span> <span style="color:#27aeae;">$i</span> <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">sed</span> -e s,build,src, <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">sed</span> -e s,output,reference, <span style="font-weight:bold;">|</span> <span style="color:#8e44ad;">sed</span> -e s,.html,.ref.html,<span style="font-weight:bold;">`</span>
    <span style="color:#8e44ad;">cp</span> -v <span style="color:#27aeae;">$i</span> <span style="color:#27aeae;">$refFile</span>
<span style="font-weight:bold;">done</span>

<span style="color:#7a7c7d;">## &gt;Settings &gt;Configure Kate &gt;Fonts &amp; Colors &gt;Highlitghing Text Styles &gt;Scripts/Bash &gt;Option &gt;Change colors to some distinct color</span>
<span style="color:#7a7c7d;">## 1- In following line the -ucode should not be colored as option</span>

<span style="color:#0099ff;font-weight:bold;">pacman</span> -Syu --needed intel-ucode grub
<span style="color:#0099ff;font-weight:bold;">pacman</span> -syu --needed intel-ucode grub

<span style="color:#7a7c7d;"># Braces (bug ##387915)</span>
<span style="font-weight:bold;">[[</span> <span style="color:#27aeae;">$line_name</span> =~ <span style="color:#2980b9;">\{</span>([0-9]<span style="color:#2980b9;">{1,}</span>)<span style="color:#2980b9;">\}\{</span>([0-9]<span style="color:#2980b9;">{1,}</span>)<span style="color:#2980b9;">\}</span>(.*)<span style="font-weight:bold;"> ]]</span>
<span style="font-weight:bold;">[[</span> <span style="color:#27aeae;">$name</span> =~ (.*)_(S[0-9]<span style="color:#2980b9;">{2}</span>)(E[0-9]<span style="color:#2980b9;">{2,3}</span>[a-z]<span style="color:#2980b9;">{0,1}</span>)_(.*)<span style="font-weight:bold;"> ]]</span>
<span style="color:#8e44ad;">rm</span> /data/<span style="color:#2980b9;">{hello1,hello2}</span>/input/<span style="color:#2980b9;">{bye1,</span><span style="color:#27aeae;">$bye2</span><span style="color:#2980b9;">}</span>/si<span style="color:#2980b9;">{a,</span><span style="color:#27aeae;">${b}</span><span style="color:#2980b9;">,c{k,p{e,a}}}</span>/*.non
<span style="color:#8e44ad;">rm</span> /data/{aa,<span style="color:#2980b9;">{e,i}</span>t<span style="color:#2980b9;">{b,c}</span> <span style="color:#7a7c7d;"># Not closed</span>
<span style="color:#8e44ad;">rm</span> /data<span style="color:#2980b9;">{aa{bb{cc{dd}}}}</span>
<span style="color:#8e44ad;">rm</span> /data<span style="color:#2980b9;">{aaa</span><span style="font-weight:bold;">`</span><span style="color:#0099ff;font-weight:bold;">aaa</span>}<span style="color:#0099ff;font-weight:bold;">aa</span><span style="font-weight:bold;">`</span><span style="color:#2980b9;">aaa}</span>a

<span style="color:#27aeae;">${array[0]: -7 : +  22  }</span>  <span style="color:#27aeae;">${array[1]: num  }</span>
<span style="color:#27aeae;">${parameter##</span>word<span style="color:#27aeae;">}</span> <span style="color:#27aeae;">${parameter%%</span>word<span style="color:#27aeae;">}</span> <span style="color:#27aeae;">${parameter^^</span>pattern<span style="color:#27aeae;">}</span> <span style="color:#27aeae;">${parameter,,</span>pattern<span style="color:#27aeae;">}</span> <span style="color:#27aeae;">${parameter@</span>operator<span style="color:#27aeae;">}</span>
</pre></body></html>
